package fr.unice.polytech.chord.samples;

import java.io.IOException;

import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.api.PAActiveObject;

import fr.unice.polytech.chord.core.Tracker;
import fr.unice.polytech.chord.samples.managers.InteractiveManager;
import fr.unice.polytech.chord.samples.managers.Manager;

/**
 * Launch a new {@link InteractiveManager} which is an instance of a console
 * mode.
 * 
 * @author Anthony Parisy
 * @author Laurent Pellegrino
 * @author Marc Valdener
 * 
 * @version 10/30/2009
 */
public class ChordLauncher {

	private String trackerURI;

	public ChordLauncher(String trackerURI) {
		this.trackerURI = trackerURI;
	}

	public void initialize() {
		Tracker remoteTrackerRef = null;

		try {
			remoteTrackerRef = (Tracker) PAActiveObject.lookupActive(
					Tracker.class.getCanonicalName(), this.trackerURI);
		} catch (ActiveObjectCreationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		Manager manager = new InteractiveManager(remoteTrackerRef);
		manager.startExecution();
	}

	public static void main(String[] args) {
		if (args.length != 1) {
			System.err.println("Usage : "
					+ ChordLauncher.class.getCanonicalName() + " trackerName");
			System.exit(1);
		}

		ChordLauncher chordLauncher = new ChordLauncher(args[0]);
		chordLauncher.initialize();
	}

}
